package com.xmg.p2p.base.service.impl;

import com.xmg.p2p.base.domain.Account;
import com.xmg.p2p.base.mapper.AccountMapper;
import com.xmg.p2p.base.service.IAccountService;
import com.xmg.p2p.base.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by zsl on 2017/10/26.
 */

@Service
public class AccountServiceImpl implements IAccountService {
	@Autowired
	private AccountMapper accountMapper;
	@Override
	public void update(Account account) {
     int ret=accountMapper.updateByPrimaryKey(account);
     if(ret==0){
     	throw new RuntimeException("乐观锁失败,Account:"+account.getId());
	 }
	}

	@Override
	public void add(Account account) {
		accountMapper.insert(account);
	}

	@Override
	public Account get(Long id) {
		return accountMapper.selectByPrimaryKey(id);
	}

	@Override
	public Account getCurrent() {
		return get(UserContext.getCurrent().getId());
	}
}
